﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Identity.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class updatepermissionbinding : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Scope",
                table: "Permissions");

            migrationBuilder.CreateTable(
                name: "PermissionKeyResourceIds",
                columns: table => new
                {
                    ResourceId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    permissionId = table.Column<Guid>(type: "uuid", nullable: false),
                    FromServiceName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    IsActive = table.Column<bool>(type: "boolean", nullable: false),
                    PermissionScope = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PermissionKeyResourceIds", x => x.ResourceId);
                    table.ForeignKey(
                        name: "FK_PermissionKeyResourceIds_Permissions_permissionId",
                        column: x => x.permissionId,
                        principalTable: "Permissions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PermissionScope",
                columns: table => new
                {
                    Value = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                });

            migrationBuilder.CreateIndex(
                name: "IX_PermissionKeyResourceIds_permissionId",
                table: "PermissionKeyResourceIds",
                column: "permissionId");

            migrationBuilder.CreateIndex(
                name: "IX_PermissionKeyResourceIds_ResourceId_FromServiceName",
                table: "PermissionKeyResourceIds",
                columns: new[] { "ResourceId", "FromServiceName" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PermissionKeyResourceIds");

            migrationBuilder.DropTable(
                name: "PermissionScope");

            migrationBuilder.AddColumn<string>(
                name: "Scope",
                table: "Permissions",
                type: "character varying(50)",
                maxLength: 50,
                nullable: false,
                defaultValue: "");
        }
    }
}
